<!DOCTYPE html>
<html>

<head>
    <title>游记列表</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/travel.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
</head>

<script>
    $(function () {
        //获取session中的用户信息
        //定义当前页初始值=1
        //定义总页数变量
        //定义存储游记的空数组
        //定义一个函数, 发送ajax-get请求,获取所有的游记
        //使用合并方法 $.merge() 把后台传过来的data合并成新的数组
        //渲染数据 renderValues  -
        //获取总页数
        //当前页+1
        //给window绑定滚动事件,调用函数
        //如果当前页大于总页, 提示用户到底了, $(document).dialog({})
        var currentPage = 1;
        var pages;
        var travelArr = [];

        function query() {
            $.get("/travels", {currentPage: currentPage}, function (data) {
                $.merge(travelArr, data.list);
                var json = {
                    list: travelArr
                };
                $('#allTravels').renderValues(json,{
                    getHref:function (item,value) {
                        $(item).attr("href",'/travelContent.html?id=/'+value);
                    }
                });
                pages = data.pages;
            });
            currentPage += 1;
        }
        query();
        $(window).scroll(function () {
            if ($(window).height() + $(document).scrollTop() >= $(document).height()) {
                if (currentPage <= pages) {
                    query();
                }else {
                    $(document).dialog({
                        type:'notice',
                        content:'<span class="info-text">到底喽</span>',
                        autoClose:2500
                    })
                }
            }
        });

        //获取每月推荐数据
        $.get('/travels/commends',{type:2,pageSize:3},function (data) {
            $('#travelsCommends').renderValues(data,{
                getHref:function (item,value) {
                    $(item).attr('href','travelContent.html?id='+value);
                }
            });
            $('.carousel-item:first').addClass('active');
        })
    })
</script>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="index.html">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜游记">
            </div>
        </div>
    </div>
</div>


<div class="container">

    <h6>每月冠军游记</h6>
    <div id="carouselExampleControls" class="carousel slide" data-ride="carousel">
        <div id="travelsCommends" class="carousel-inner" render-loop="list">
            <div>
                <div class="carousel-item">
                    <div class="border commend">
                        <a render-key="list.t_id" render-fun="getHref" data-href="/travelContent.html?id=">
                            <img render-src="list.coverUrl" width="100%" height="200px">
                            <h1 render-html="list.title"></h1>
                            <small render-html="list.r_name"></small>
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">
            <span class="carousel-control-prev-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
        <a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">
            <span class="carousel-control-next-icon" aria-hidden="true"></span>
            <span class="sr-only"></span>
        </a>
    </div>
</div>

<div class="container">
    <h6>全部游记</h6>

    <div id="allTravels">
        <div render-loop="list">
            <div class="row detail">
                <div class="col">
                    <a render-fun="getHref" render-key="list.id">
                        <h4 render-html="list.title"></h4>
                    </a>
                    <p>
                        <a href="userProfiles.html">
                            <img class="rounded-circle head-img"
                                 render-src="list.author.headImgUrl">
                            <span render-html="list.author.nickName"></span> </a> 在
                        <span class="addr" render-html="list.place.name"></span>
                    </p>
                    <p>
                        <i class="fa fa-eye fa-fw"></i>
                        <span>0</span>
                        <i class="fa fa-commenting fa-fw"></i>
                        <span>0</span>
                    </p>
                </div>
                <div class="col bigimg">
                    <a render-fun="getHref" render-key="list.id">
                        <img render-src="list.coverUrl">
                    </a>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

</html>